﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ModelLayer;
using DAL;

namespace BusinessLayer
{
    public class TokenB : IFTokenB
    {
        public TokenB()
        {

        }

        public ModelLayer.Token CreateToken(int userid)
        {
            IFSecurity security = new Security();
            string tokenhash = security.GenerateTokenHash();
            TimeSpan timeSpan = DateTime.UtcNow.AddYears(1) - new DateTime(1970, 1, 1, 0, 0, 0);
            TokenDB token = new TokenDB();
            return token.CreateToken(userid, tokenhash, (int)timeSpan.TotalSeconds);
        }


        public ModelLayer.Token FindToken(int userId)
        {
            
            TokenDB tdb = new TokenDB();
            return tdb.FindToken(userId);
        }

        public void DeleteToken(int uid)
        {
            TokenDB db = new TokenDB();
            db.DeleteToken(uid);
        }
    }
}
